package com.dajingling.service.impl;

import com.dajingling.bean.Bills;
import com.dajingling.dao.BillsMapper;
import com.dajingling.service.BillTypeService;
import com.dajingling.service.BillsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//创建对象
@Service
public class BillsServiceImpl implements BillsService {
    @Resource
    private BillsMapper billsMapper;
    @Override
    public PageInfo<Bills> getBills(int typeid,String begin,String end,int index,int size) {
        Map map = new HashMap();
        map.put("tid",typeid);
        map.put("begin",begin);
        map.put("end",end);
        //1.指定分页数据
        PageHelper.startPage(index,size);
        //2.查询数据
        List<Bills> bills = billsMapper.getBills(map);
        //3.创建分页工具类
        PageInfo<Bills> info = new PageInfo<>(bills);
        return info;
    }

    @Transactional
    @Override
    public int insert(Bills record) {
        return billsMapper.insert(record);
    }

    @Override
    public Bills selectByPrimaryKey(Integer id) {
        return billsMapper.selectByPrimaryKey(id);
    }

    @Transactional
    @Override
    public int updateByPrimaryKey(Bills record) {
        return billsMapper.updateByPrimaryKey(record);
    }

    @Transactional
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return billsMapper.deleteByPrimaryKey(id);
    }
}
